﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Legazpi.Payroll.BusinessLogic.Services;
using Ninject;
using Legazpi.Payroll.BusinessLogic.Services.Interfaces;

namespace Legazpi.Payroll.Web.Usercontrols
{
    public partial class EmployeeSearchControl : System.Web.UI.UserControl
    {
        [Inject]
        public  IEmployeeService _employeeService { get; set;}               

        #region Implementations
        void BindGrid()
        {            
            repeater.DataSource = _employeeService.Get(0, 15)
                .Select(x => new
                {
                    Id = x.Id,
                    EmployeeCode = x.EmployeeCode,
                    Fullname = string.Format("{0}, {1} {2}", x.LastName, x.FirstName, x.MiddleName),
                    Nickname = x.NickName,
                    Added = x.DateAdded.HasValue ? x.DateAdded.Value.ToShortDateString() : "n/a",
                    Position = x.Position.Code.ToString()
                }).ToList();

            repeater.DataBind();        
        }

        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            BindGrid();
        }
        protected void btnAddNewEmployee_Click(object sender, EventArgs e)
        {
            Response.Redirect(ResolveUrl("~/Admin/EmployeeView.aspx/"));
        }
    }

}